<?php

/**
 * 扩展控制器
 * @author 		jaypha
 * @qq			168007694
 * @email		psufool@163.com
 * @home page	www.psufool.cn
 */
class Jaypha_Controller extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('date');
        $this->load->helper('pinyin');
        $this->load->driver('cache');
        $this->load->library('pagination');
    }

    /**
     * 截取字符串
     * @param $string				待截取的字符串
     * @param $length				截取长度
     * @param $encoding				字符编码
     */
    protected function substr($string, $length=0, $encoding='utf-8')
    {
        $string = trim($string);
        if ($length && strlen($string) > $length)
        {
            //截断字符  
            $wordscut = '';
            if (strtolower($encoding) == 'utf-8')
            {
                //utf8编码  
                $n = 0;
                $tn = 0;
                $noc = 0;
                while ($n < strlen($string))
                {
                    $t = ord($string[$n]);
                    if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126))
                    {
                        $tn = 1;
                        $n++;
                        $noc++;
                    } elseif (194 <= $t && $t <= 223)
                    {
                        $tn = 2;
                        $n += 2;
                        $noc += 2;
                    } elseif (224 <= $t && $t < 239)
                    {
                        $tn = 3;
                        $n += 3;
                        $noc += 2;
                    } elseif (240 <= $t && $t <= 247)
                    {
                        $tn = 4;
                        $n += 4;
                        $noc += 2;
                    } elseif (248 <= $t && $t <= 251)
                    {
                        $tn = 5;
                        $n += 5;
                        $noc += 2;
                    } elseif ($t == 252 || $t == 253)
                    {
                        $tn = 6;
                        $n += 6;
                        $noc += 2;
                    } else
                    {
                        $n++;
                    }
                    if ($noc >= $length)
                    {
                        break;
                    }
                }
                if ($noc > $length)
                {
                    $n -= $tn;
                }
                $wordscut = substr($string, 0, $n);
            } else
            {
                for ($i = 0; $i < $length - 1; $i++)
                {
                    if (ord($string[$i]) > 127)
                    {
                        $wordscut .= $string[$i] . $string[$i + 1];
                        $i++;
                    } else
                    {
                        $wordscut .= $string[$i];
                    }
                }
            }
            $string = $wordscut;
        }
        return trim($string);
    }

}

/**
 * 后台控制器
 * @author 		jaypha
 * @qq			168007694
 * @email		psufool@163.com
 * @home page	www.psufool.cn
 */
class Admin_Controller extends Jaypha_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->library('ckeditor');
        $this->load->library('ckFinder');
        $this->adminCurrentTemplate = 'default';
    }

    /**
     * 判断是否登陆后台
     */
    private function isLogin()
    {
        return $this->session->userdata('adminIsOnline');
    }

    /**
     * 打印输出登陆状态
     */
    function writeIsLogin()
    {
        echo $this->isLogin();
    }

    /**
     * 判断是否登陆，如果未登陆则显示错误信息！
     */
    function noLoginErr()
    {
        if (!$this->isLogin())
        {
            $data['errorScript'] = array('lhgdialog_alert_mess_top' => array(
                    'width' => 385,
                    'height' => 108,
                    'title' => '越权操作',
                    'content' => '<span class="red">对不起，您还未登陆，不允许进行操作，请登陆后重试！</span>',
                    'url' => site_url('admin/login'),
                    'target' => '_top',
                    'conver' => true,
                    'resize' => false,
                    'drag' => true,
                    'btns' => true,
                    'btnText' => '登 陆',
                    'rightClose' => false
                    ));
            $this->load->view("admin/$this->adminCurrentTemplate/error", $data);
            return false;
        } else
        {
            return true;
        }
    }

}

/**
 * 前台控制器
 * @author 		jaypha
 * @qq			168007694
 * @email		psufool@163.com
 * @home page	www.psufool.cn
 */
class Front_Controller extends Jaypha_Controller
{
	protected $assignData = array();
    function __construct()
    {
        parent::__construct();
        $this->load->model('JayphaDB');
        $this->load->model('JayphaTemplate');
        $this->db_table_prefix = $this->config->item('db_table_prefix');
        /*$this->operational_str = array('!=', '>=', '<=', '>', '<', '=');
        $this->operational_str2 = array('and', ' or ', 'not');
        $this->page_config = array();
        $this->frontCurrentTemplate = $this->JayphaDB->getConfigValue('frontCurrentTemplate');
        $frontPageSize = $this->JayphaDB->getConfigValue('frontPageSize');
        */
        $this->setWebTitle();
        $this->setWebKeyword();
        $this->setWebDesc();
    }
	
    /*
     * 设置网页标题
     */
    protected function setWebTitle($title='', $cover=false) {
    	if (!empty($title)) {
    		if ($cover !== false) {
    			$webTitle = $title;
    		} else {
    			$webTitle = $title.$this->config->item('web_title_sign').$this->config->item('web_title');
    		}
    	} else {
    		$webTitle = $this->config->item('web_title');
    	}
    	$this->assignData['web_title'] = $webTitle;
    	return;
    }
    
    //设置关键字
    protected function setWebKeyword($keyword='', $cover=false) {
    	if (!empty($keyword)) {
    		if ($cover !== false) {
    			$webKeyword = $keyword;
    		} else {
    			$webKeyword = $this->config->item('web_keyword').$this->config->item('web_keyword_sign').$keyword;
    		}
    	} else {
    		$webKeyword = $this->config->item('web_keyword');
    	}
    	$this->assignData['web_keyword'] = $webKeyword;
    	return;
    }
    
    /*
     * 设置网站描述
     */
    protected function setWebDesc($content='', $cover=false) {
    	if (!empty($content)) {
    		if ($cover  !== false) {
    			$webDesc = $content;
    		} else {
    			$webDesc = $this->config->item('web_desc').$content;
    		}
    	} else {
    		$webDesc = $this->config->item('web_desc');
    	}
    	$this->assignData['web_desc'] = $webDesc;
    	return;
    }
    
    /*
     * 错误提示页面
     */
    protected  function showmsg($msg='', $url='', $time=3) {
    	$this->assignData['msg'] = $msg;
    	$this->assignData['url'] = $url;
    	$this->assignData['time'] = $time;
    	$this->setWebTitle('消息提示');
		$this->load->view('msg', $this->assignData);
    }
    
    /*
     * 获取客户端的IP地址
     */
	protected function get_client_ip() {
		$ip = '';
		$cip = getenv('HTTP_CLIENT_IP');
		$xip = getenv('HTTP_QW_FORWARDED_FOR');
		$rip = getenv('REMOTE_ADDR');
		$srip = $_SERVER['REMOTE_ADDR'];
		if($cip && strcasecmp($cip, 'unknown')) {
			$ip = $cip;
		} elseif($xip && strcasecmp($xip, 'unknown')) {
			$ip = $xip;
		} elseif($rip && strcasecmp($rip, 'unknown')) {
			$ip = $rip;
		} elseif($srip && strcasecmp($srip, 'unknown')) {
			$ip = $srip;
		}
		return $ip;
	}

    /**
     * 获取总页数
     * @param $recordTotal			记录总数
     * @param $pageSize				分页大小 ，默认则为系统统配置的前台默认分页大小
     */
    function getPageTotal($recordTotal, $pageSize='')
    {
        if (strlen($pageSize) == 0)
            $pageSize = $frontPageSize;
        if (!is_numeric($recordTotal) || !is_numeric($pageSize))
            return 0;
        if ($recordTotal <= 0 || $pageSize <= 0)
            return 0;
        if ($recordTotal % $pageSize == 0)
            return (int) ($recordTotal / $pageSize);
        else
            return (int) ($recordTotal / $pageSize) + 1;
    }

    /**
     * 通过属性设置字符串
     * @param $attributeName			属性名称
     * @param $attributeValue			属性值
     * @param $string					待设置的字符串
     * @return 							返回字符串
     */
    protected function setStringAttribute($attributeName, $attributeValue, $string, $phpcode='')
    {
        switch (strtoupper($attributeName))
        {
            case strtoupper('formatNumber'):
                //判断是否为数字，若不是数字，则不进行处理此属性
                if (!is_numeric($string))
                    break;
                if (strlen($attributeValue) == 0)
                {
                    //形如：1,000,000
                    $string = number_format($string);
                } else
                {
                    $attr_arr = explode('|', $attributeValue);
                    if (is_numeric($attr_arr[0]))
                    {
                        switch (count($attr_arr))
                        {
                            case 3:
                                //形如(2|.|,)：小数点位数|小数点字符|千分位分隔符
                                $string = number_format($string, $attr_arr[0], $attr_arr[1], $attr_arr[2]);
                                break;
                            default:
                                //小数点位数							
                                $string = number_format($string, $attr_arr[0]);
                                break;
                        }
                    }
                }
                break;
            case strtoupper('formatTime'):
                //格式化时间
                if (strlen($attributeValue) == 0)
                    break;
                if (!is_numeric($string))
                {
                    $string = strtotime($string);
                }
                $string = date($attributeValue, $string);
                break;
            case strtoupper('format'):
                //格式化字符串
                if (strlen($attributeValue) == 0)
                    break;
                if (substr($attributeValue, 0, 1) != '%')
                    break;
                $string = sprintf($attributeValue, $string);
                break;
            case strtoupper('len'):
            case strtoupper('length'):
                //获取指定长度
                if (!is_numeric($attributeValue))
                    break;
                $string = $this->substr($string, $attributeValue);
                break;
            case strtoupper('filterHtml'):
                //过滤HTML
                if (strlen($attributeValue) != 0)
                {
                    if (stristr($attributeValue, '|'))
                    {
                        $attr_arr = explode('|', $attributeValue);
                        if (strlen($attr_arr[0]) == 0)
                            $attr_arr[0] = 'all';
                        if (strlen($attr_arr[1]) == 0)
                        {
                            $attr_arr[1] = 0;
                        } else if (!is_numeric($attr_arr[1]))
                        {
                            $attr_arr[1] = 0;
                        }
                        $string = $this->JayphaTemplate->filterHtml($string, $attr_arr[0], $attr_arr[1]);
                    } else
                    {
                        if (strtolower($attributeValue) == 'all')
                        {
                            $string = $this->JayphaTemplate->filterHtml($string);
                        } else
                        {
                            $string = $this->JayphaTemplate->filterHtml($string, $attributeValue);
                        }
                    }
                } else
                {
                    $string = $this->JayphaTemplate->filterHtml($string);
                }
                break;
            case strtoupper('filterSpace'):
                //是否过滤空格(包括“ ”、“&nbsp;”及中文空格“　”)
                $attributeValue = trim($attributeValue);
                if (strlen($attributeValue) == 0)
                    break;
                $attributeValue = (strtolower($attributeValue) === 'true' || $attributeValue === '1') ? true : false;
                if ($attributeValue)
                {
                    $filterstr = array(' ', '&nbsp;', '　');
                    $string = str_ireplace($filterstr, '', $string);
                }
                break;
            case strtoupper('filterChar'):
                //过滤指定字符串，多个用一个空格(“ ”)分隔
                if (strlen($attributeValue) == 0)
                    break;
                $char_arr = explode(' ', $attributeValue);
                $string = str_ireplace($char_arr, '', $string);
                break;
            case strtoupper('function'):
                //使用系统方法
                if (strlen($attributeValue) == 0)
                    break;
                $attributeValue = str_ireplace(array('exit', 'die'), '', $attributeValue);
                $attributeValue = str_ireplace('@me', $string, $attributeValue);
                $attributeValue = "\$string = $attributeValue;";
                $__num_ = strpos($attributeValue, ';', 0);
                $attributeValue = substr($attributeValue, 0, $__num_ + 1);
                @eval($attributeValue);
                break;
            case strtoupper('runphp'):
                //运行PHP代码
                $attributeValue = trim($attributeValue);
                $phpcode = trim($phpcode);
                if (strlen($attributeValue) == 0)
                    break;
                $attributeValue = (strtolower($attributeValue) === 'true' || strtolower($attributeValue) === 'yes' || $attributeValue === '1') ? true : false;
                if ($attributeValue && strlen($phpcode) > 0)
                {
                    if (stristr($phpcode, '@me'))
                    {
                        $me_variable = $string;
                        if (substr($phpcode, strlen($phpcode) - 1) != ';')
                            $phpcode .= ';';
                        $phpcode = str_ireplace('@me', "\$me_variable", $phpcode) . "\n\$string = \$me_variable;";
                        @eval($phpcode);
                    }
                }
                break;
        }
        return $string;
    }

    /**
     * 初始化模板字符串
     * @param $templateString			模板字符串
     */
    protected function init($templateString)
    {
        return $templateString;
    }

    /**
     * {field}标签
     * @param $templateString
     */
    protected function display_field($templateString)
    {
        //获取field标签
        $field_tag = $this->JayphaTemplate->fieldTag($templateString);
        //获取当前控制器
        $channel_identifier = $this->uri->segment(1, '');
        //判断当前控制器是否为空，为空则说明是首页，不进行field标签解析
        if (strlen($channel_identifier) == 0)
            return $templateString;
        //根据当前控制器，获取模型
        $channel = $this->JayphaDB->getDB(0, 1, '', $this->db_table_prefix . 'channel', array('lower(identifier)' => strtolower($channel_identifier)), '', true);
        foreach ($channel as $item)
        {
            //主表
            $main_table = "archives";
            //页面类型
            $type = $this->uri->segment(2, '');
            if (strlen($type) == 0)
                $type = 'index';
            $id = $this->uri->segment(3, 0);
            switch (strtolower($type))
            {
                case 'content':
                    //内容页
                    $field_list = $this->db_table_prefix . $main_table . '.*';
                    $subjoin_table = $item->subjoinTable;
                    $subjoin_field = $this->JayphaTemplate->getSubjoinFields($item->fieldset, 1);
                    foreach ($subjoin_field as $subjoin_field_item)
                    {
                        $field_list .= ',' . $this->db_table_prefix . $subjoin_table . '.' . $subjoin_field_item;
                    }
                    $table_list = array('tableName' => $this->db_table_prefix . $main_table
                        , 'db_join' => array(array('tableName' => $this->db_table_prefix . $subjoin_table
                                , 'conditions' => $this->db_table_prefix . $main_table . '.id=' . $this->db_table_prefix . $subjoin_table . '.aid')));
                    $where = array($this->db_table_prefix . $main_table . '.id' => $id);
                    break;
                default:
                    //栏目页
                    $field_list = $this->db_table_prefix . 'category.*';
                    $field_list .= ',' . $this->db_table_prefix . 'channel.subjoinTable';
                    $field_list .= ',' . $this->db_table_prefix . 'channel.mainTable';
                    $field_list .= ',' . $this->db_table_prefix . 'channel.title as channeltitle';
                    $table_list = array('tableName' => $this->db_table_prefix . 'category',
                        'db_join' => array(
                            array('tableName' => $this->db_table_prefix . 'channel', 'conditions' => $this->db_table_prefix . 'category.channelId=' . $this->db_table_prefix . 'channel.id')
                            ));
                    $where = array($this->db_table_prefix . 'category.id' => $id);
                    break;
            }
            //从数据库中获取数据
            $list_db = $this->JayphaDB->getDB(0, 1, $field_list, $table_list, $where, '', true);
            //将字段名全部转换为小写
            $list_db2 = array();
            for ($list_db2_i = 0; $list_db2_i < count($list_db); $list_db2_i++)
            {
                foreach ($list_db[$list_db2_i] as $key => $value)
                {
                    $key = strtolower($key);
                    $list_db2[$list_db2_i]->$key = $value;
                }
            }
            $list_db = $list_db2;
            unset($list_db2);
            foreach ($list_db as $list_row)
            {
                if (strtolower($type) == 'content')
                {
                    $updata = array('click' => $list_row->click + 1);
                    $this->JayphaDB->updateDB($updata, $this->db_table_prefix . $main_table, array('id' => $id));
                }
                foreach ($field_tag as $field_tag_item)
                {
                    $field_tag_full = $field_tag_item[0];
                    $field_tag_name = strtolower($field_tag_item[1]);
                    $field_tag_attr = $field_tag_item[2];
                    @$field_run_php_code = $field_tag_item[3];
                    $field_tag_value = $list_row->$field_tag_name;
                    if (is_array($field_tag_attr))
                    {
                        foreach ($field_tag_attr as $tag_attr_name => $tag_attr_value)
                        {
                            if (strtolower($tag_attr_name) == 'runphp')
                            {
                                $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value, $field_run_php_code);
                            } else
                            {
                                $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value);
                            }
                        }
                    }
                    $templateString = str_ireplace($field_tag_full, $field_tag_value, $templateString);
                }
            }
        }
        return $templateString;
    }

    /**
     * 系统标签
     * @param $templateString			模板字符串
     * @return 							返回解析系统标签之后的字符串
     */
    protected function display_sys($templateString)
    {
        $sys_tag = $this->JayphaTemplate->sysTag($templateString);
        foreach ($sys_tag as $tag_name => $tag_str)
        {
            $templateString = str_ireplace($tag_str, $this->JayphaDB->getConfigValue($tag_name), $templateString);
        }
        return $templateString;
    }

    /**
     * 导入标签
     * @param $templateString			模板字符串
     * @return 							返回解析导入标签之后的字符串
     */
    protected function display_inc($templateString, $data=null)
    {
        $str_inc = $this->JayphaTemplate->incTag($templateString);
        while (count($str_inc) > 0)
        {
            foreach ($str_inc as $file => $tag_str)
            {
                if (strlen($this->frontCurrentTemplate) > 0)
                {
                    if (substr($this->frontCurrentTemplate, strlen($this->frontCurrentTemplate) - 1) != '/')
                    {
                        if (substr($file, 0, 1) != '/')
                        {
                            $file = $this->frontCurrentTemplate . '/' . $file;
                        } else
                        {
                            $file = $this->frontCurrentTemplate . $file;
                        }
                    } else
                    {
                        if (substr($file, 0, 1) != '/')
                        {
                            $file = $this->frontCurrentTemplate . $file;
                        } else
                        {
                            $file = substr($this->frontCurrentTemplate, 0, strlen($this->frontCurrentTemplate) - 1) . $file;
                        }
                    }
                }
                $templateString = str_ireplace($tag_str, $this->load->view($file, $data, true), $templateString);
            }
            $str_inc = $this->JayphaTemplate->incTag($templateString);
        }
        return $templateString;
    }

    /**
     * 判断标签
     * @param $templateString			模板字符串
     * @return 							返回解析判断标签之后的字符串
     */
    protected function display_if($templateString)
    {
        $str_if = $this->JayphaTemplate->ifTag($templateString);
        for ($i = 0; $i < count($str_if[0]); $i++)
        {
            @$str_if[1][$i] = str_ireplace("\n", "", $str_if[1][$i]);
            @$templateString = str_ireplace($str_if[0][$i], $str_if[1][$i], $templateString);
        }
        return $templateString;
    }

    /**
     * 列表标签
     * @param $templateString			模板字符串
     * @return 							返回解析列表标签之后的字符串
     */
    protected function display_list($templateString)
    {
        $str_list = $this->JayphaTemplate->listTag($templateString);
        if (count($str_list) == 0)
            return $templateString;
        foreach ($str_list as $list_item)
        {
            //过滤重复记录，默认不过滤
            $distinct = $list_item[1]['distinct'];
            if (strlen($distinct) == 0)
                $distinct = false;
            //获取字段
            $field = $list_item[1]['field'];
            if (strlen($field) > 0)
            {
                $field = str_ireplace('#@__', $this->db_table_prefix, $field);
            }
            //获取表
            if (strlen($list_item[1]['table']) == 0)
            {
                continue;
            } else
            {
                $tvName = $list_item[1]['table'];
            }
            $tvName = str_ireplace('#@__', $this->db_table_prefix, $tvName);
            //判断是否存在关联数据表
            if (strlen($list_item[1][strtolower('joinTable')]) > 0 && strlen($list_item[1][strtolower('joinOn')]) > 0)
            {
                $join_table = explode(',', $list_item[1][strtolower('joinTable')]);
                $join_on = explode(',', $list_item[1][strtolower('joinOn')]);
                $join_type = explode(',', $list_item[1][strtolower('joinType')]);
                $db_join_arr = array();
                for ($i = 0; $i < count($join_table); $i++)
                {
                    $join_on[$i] = str_ireplace('#@__', $this->db_table_prefix, $join_on[$i]);
                    $join_table[$i] = str_ireplace('#@__', $this->db_table_prefix, $join_table[$i]);
                    if (!isset($join_type[$i]))
                        $join_type[$i] = 'inner';
                    if (strlen($join_type[$i]) == 0)
                        $join_type[$i] = 'inner';
                    $db_join_arr[$i] = array('tableName' => $join_table[$i], 'conditions' => $join_on[$i], 'joinType' => $join_type[$i]);
                }
                $tvName = array(
                    'tableName' => $tvName,
                    'db_join' => $db_join_arr
                );
            }
            //where
            $where = array();
            if (strlen(trim($list_item[1]['where'])) > 0)
            {
                $list_item[1]['where'] = str_ireplace('#@__', $this->db_table_prefix, $list_item[1]['where']);
                $list_item[1]['where'] = str_ireplace(' ', '', $list_item[1]['where']);
                foreach ($this->operational_str as $opearational_str)
                {
                    $list_item[1]['where'] = str_ireplace($opearational_str, ' ' . $opearational_str, $list_item[1]['where']);
                }
                foreach ($this->operational_str2 as $opearational_str2)
                {
                    $list_item[1]['where'] = str_ireplace($opearational_str2, ' ' . trim($opearational_str2) . ' ', $list_item[1]['where']);
                }
                $where['db_where'] = $list_item[1]['where'];
            }
            //where_in
            if (strlen(trim($list_item[1][strtolower('whereIn')])) > 0 && strlen(trim($list_item[1][strtolower('whereInField')])) > 0)
            {
                $list_item[1][strtolower('whereIn')] = str_ireplace(' ', '', $list_item[1][strtolower('whereIn')]);
                $list_item[1][strtolower('whereIn')] = explode(',', $list_item[1][strtolower('whereIn')]);
                $list_item[1][strtolower('whereInField')] = str_ireplace('#@__', $this->db_table_prefix, $list_item[1][strtolower('whereInField')]);
                $where['db_where_in'] = array($list_item[1][strtolower('whereInField')], $list_item[1][strtolower('whereIn')]);
            }
            //where_like
            if (strlen(trim($list_item[1]['like'])) > 0 && strlen(trim($list_item[1][strtolower('likeField')])) > 0)
            {
                $list_item[1][strtolower('likeField')] = str_ireplace('#@__', $this->db_table_prefix, $list_item[1][strtolower('likeField')]);
                $list_item[1]['like'] = str_ireplace(' ', '', $list_item[1]['like']);
                $where['db_like'] = array('upper(' . $list_item[1][strtolower('likeField')] . ')' => strtoupper($list_item[1]['like']));
            }
            //where_not_like
            if (strlen(trim($list_item[1][strtolower('notLike')])) > 0 && strlen(trim($list_item[1][strtolower('notLikeField')])) > 0)
            {
                $list_item[1][strtolower('notLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $list_item[1][strtolower('notLikeField')]);
                $list_item[1][strtolower('notLike')] = str_ireplace(' ', '', $list_item[1][strtolower('notLike')]);
                $where['db_not_like'] = array('upper(' . $list_item[1][strtolower('notLikeField')] . ')' => strtoupper($list_item[1][strtolower('notLike')]));
            }
            //where_or_like
            if (strlen(trim($list_item[1][strtolower('orLike')])) > 0 && strlen(trim($list_item[1][strtolower('orLikeField')])) > 0)
            {
                $list_item[1][strtolower('orLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $list_item[1][strtolower('orLikeField')]);
                $list_item[1][strtolower('orLike')] = str_ireplace(' ', '', $list_item[1][strtolower('orLike')]);
                $where['db_or_like'] = array('upper(' . $list_item[1][strtolower('orLikeField')] . ')' => strtoupper($list_item[1][strtolower('orLike')]));
            }
            //where_or_not_like
            if (strlen(trim($list_item[1][strtolower('orNotLike')])) > 0 && strlen(trim($_list_item[1][strtolower('orNotLikeField')])) > 0)
            {
                $list_item[1][strtolower('orNotLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $this_item[1][strtolower('orNotLikeField')]);
                $list_item[1][strtolower('orNotLike')] = str_ireplace(' ', '', $list_item[1][strtolower('orNotLike')]);
                $where['db_or_not_like'] = array('upper(' . $list_item[1][strtolower('orNotLikeField')] . ')' => strtoupper($list_item[1][strtolower('orNotLike')]));
            }

            //排序
            $order = $list_item[1]['order'];
            if (strlen($order) > 0)
            {
                $order = str_ireplace('#@__', $this->db_table_prefix, $order);
            }
            //获取记录数
            $top = $list_item[1]['top'];
            if (strlen($top) == 0)
                $top = 0;
            //从数据库从读取记录
            $list_db = $this->JayphaDB->getDB(0, $top, $field, $tvName, $where, $order, $distinct);
            //将字段名全部转换为小写
            $list_db2 = array();
            for ($list_db2_i = 0; $list_db2_i < count($list_db); $list_db2_i++)
            {
                foreach ($list_db[$list_db2_i] as $key => $value)
                {
                    $key = strtolower($key);
                    $list_db2[$list_db2_i]->$key = $value;
                }
            }
            $list_db = $list_db2;
            unset($list_db2);

            $list_item_string = '';
            $this_num = 0;
            foreach ($list_db as $list_row)
            {
                $this_num++;
                $list_row_string = $list_item[2];
                for ($i3 = 0; $i3 < count($list_item[3]); $i3++)
                {
                    $field_tag = $list_item[3][$i3][0];
                    $field_tag_name = strtolower($list_item[3][$i3][1]);
                    $field_tag_attr = $list_item[3][$i3][2];
                    @$field_run_php_code = $list_item[3][$i3][3];
                    if (strtolower($field_tag_name) == 'thiscount')
                    {
                        $field_tag_value = count($list_db);
                    } elseif (strtolower($field_tag_name) == 'thisnum')
                    {
                        $field_tag_value = $this_num;
                    } else
                    {
                        $field_tag_value = $list_row->$field_tag_name;
                    }
                    if (is_array($field_tag_attr))
                    {
                        foreach ($field_tag_attr as $tag_attr_name => $tag_attr_value)
                        {
                            if (strtolower($tag_attr_name) == 'runphp')
                            {
                                $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value, $field_run_php_code);
                            } else
                            {
                                $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value);
                            }
                            //$field_tag_value = $this->setStringAttribute($tag_attr_name,$tag_attr_value,$field_tag_value);
                        }
                    }
                    $list_row_string = str_ireplace($field_tag, $field_tag_value, $list_row_string);
                }
                $list_item_string .= $list_row_string;
            }
            $templateString = str_ireplace($list_item[0], $list_item_string, $templateString);
        }
        return $templateString;
    }

    /**
     * do循环标签
     * @param $templateString				模板字符串
     * @return 								返回解析do循环标签后的字符串
     */
    protected function display_do($templateString)
    {
        $str_do = $this->JayphaTemplate->doTag($templateString);
        if (count($str_do) == 0)
            return $templateString;
        foreach ($str_do as $do_item)
        {
            //过滤重复记录，默认不过滤
            $distinct = $do_item[2]['distinct'];
            if (strlen($distinct) == 0)
                $distinct = false;
            //获取字段
            $field = $do_item[2]['field'];
            if (strlen($field) > 0)
                $field = str_ireplace('#@__', $this->db_table_prefix, $field);
            //获取表
            if (strlen($do_item[2]['table']) == 0)
                continue;
            $tvName = $do_item[2]['table'];
            $tvName = str_ireplace('#@__', $this->db_table_prefix, $tvName);
            //判断是否存在关联数据表
            if (strlen($do_item[2]['joinon']) > 0 && strlen($do_item[2]['jointable']) > 0)
            {
                $join_table = explode(',', $do_item[2][strtolower('joinTable')]);
                $join_on = explode(',', $do_item[2][strtolower('joinOn')]);
                $join_type = explode(',', $do_item[2][strtolower('joinType')]);
                $db_join_arr = array();
                for ($i = 0; $i < count($join_table); $i++)
                {
                    $join_on[$i] = str_ireplace('#@__', $this->db_table_prefix, $join_on[$i]);
                    $join_table[$i] = str_ireplace('#@__', $this->db_table_prefix, $join_table[$i]);
                    if (!isset($join_type[$i]))
                        $join_type[$i] = 'inner';
                    if (strlen($join_type[$i]) == 0)
                        $join_type[$i] = 'inner';
                    $db_join_arr[$i] = array('tableName' => $join_table[$i], 'conditions' => $join_on[$i], 'joinType' => $join_type[$i]);
                }
                $tvName = array(
                    'tableName' => $tvName,
                    'db_join' => $db_join_arr
                );
            }
            //where
            $where = array();
            if (strlen(trim($do_item[2]['where'])) > 0)
            {
                $do_item[2]['where'] = str_ireplace('#@__', $this->db_table_prefix, $do_item[2]['where']);
                $do_item[2]['where'] = str_ireplace(' ', '', $do_item[2]['where']);
                foreach ($this->operational_str as $opearational_str)
                {
                    $do_item[2]['where'] = str_ireplace($opearational_str, ' ' . $opearational_str, $do_item[2]['where']);
                }
                foreach ($this->operational_str2 as $opearational_str2)
                {
                    $do_item[1]['where'] = str_ireplace($opearational_str2, ' ' . trim($opearational_str2) . ' ', $do_item[1]['where']);
                }
                $where['db_where'] = $do_item[2]['where'];
            }
            //where_in
            if (strlen(trim($do_item[2][strtolower('whereIn')])) > 0 && strlen(trim($do_item[2][strtolower('whereInField')])) > 0)
            {
                $do_item[2][strtolower('whereIn')] = str_ireplace(' ', '', $do_item[2][strtolower('whereIn')]);
                $do_item[2][strtolower('whereIn')] = explode(',', $do_item[2][strtolower('whereIn')]);
                $do_item[2][strtolower('whereInField')] = str_ireplace('#@__', $this->db_table_prefix, $do_item[2][strtolower('whereInField')]);
                $where['db_where_in'] = array($do_item[2][strtolower('whereInField')], $do_item[2][strtolower('whereIn')]);
            }
            //where_like
            if (strlen(trim($do_item[2]['like'])) > 0 && strlen(trim($do_item[2][strtolower('likeField')])) > 0)
            {
                $do_item[2][strtolower('likeField')] = str_ireplace('#@__', $this->db_table_prefix, $do_item[2][strtolower('likeField')]);
                $do_item[2]['like'] = str_ireplace(' ', '', $do_item[2]['like']);
                $where['db_like'] = array('upper(' . $do_item[2][strtolower('likeField')] . ')' => strtoupper($do_item[2]['like']));
            }
            //where_not_like
            if (strlen(trim($do_item[2][strtolower('notLike')])) > 0 && strlen(trim($do_item[2][strtolower('notLikeField')])) > 0)
            {
                $do_item[2][strtolower('notLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $do_item[2][strtolower('notLikeField')]);
                $do_item[2][strtolower('notLike')] = str_ireplace(' ', '', $do_item[2][strtolower('notLike')]);
                $where['db_not_like'] = array('upper(' . $do_item[2][strtolower('notLikeField')] . ')' => strtoupper($do_item[2][strtolower('notLike')]));
            }
            //where_or_like
            if (strlen(trim($do_item[2][strtolower('orLike')])) > 0 && strlen(trim($do_item[2][strtolower('orLikeField')])) > 0)
            {
                $do_item[2][strtolower('orLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $do_item[2][strtolower('orLikeField')]);
                $do_item[2][strtolower('orLike')] = str_ireplace(' ', '', $do_item[2][strtolower('orLike')]);
                $where['db_or_like'] = array('upper(' . $do_item[2][strtolower('orLikeField')] . ')' => strtoupper($do_item[2][strtolower('orLike')]));
            }
            //where_or_not_like
            if (strlen(trim($do_item[2][strtolower('orNotLike')])) > 0 && strlen(trim($_list_item[1][strtolower('orNotLikeField')])) > 0)
            {
                $do_item[2][strtolower('orNotLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $this_item[1][strtolower('orNotLikeField')]);
                $do_item[2][strtolower('orNotLike')] = str_ireplace(' ', '', $do_item[2][strtolower('orNotLike')]);
                $where['db_or_not_like'] = array('upper(' . $do_item[2][strtolower('orNotLikeField')] . ')' => strtoupper($do_item[2][strtolower('orNotLike')]));
            }

            //排序
            $order = $do_item[2]['order'];
            if (strlen($order) > 0)
            {
                $order = str_ireplace('#@__', $this->db_table_prefix, $order);
            }
            //获取记录数
            $top = $do_item[2]['top'];
            if (strlen($top) == 0)
                $top = 0;
            //从数据库从读取记录
            $list_db = $this->JayphaDB->getDB(0, $top, $field, $tvName, $where, $order, $distinct);
            //将字段名全部转换为小写
            $list_db2 = array();
            for ($list_db2_i = 0; $list_db2_i < count($list_db); $list_db2_i++)
            {
                foreach ($list_db[$list_db2_i] as $key => $value)
                {
                    $key = strtolower($key);
                    $list_db2[$list_db2_i]->$key = $value;
                }
            }
            $list_db = $list_db2;
            unset($list_db2);

            $do_item_string = '';
            $this_num = 0;
            foreach ($list_db as $list_row)
            {
                $this_num++;
                $list_row_string = $do_item[4];
                for ($i3 = 0; $i3 < count($do_item[3]); $i3++)
                {
                    $field_tag = $do_item[3][$i3][0];
                    $field_tag_name = strtolower($do_item[3][$i3][1]);
                    $field_tag_attr = $do_item[3][$i3][2];
                    $field_run_php_code = $do_item[3][$i3][3];
                    if (strtolower($field_tag_name) == 'thiscount')
                    {
                        $field_tag_value = count($list_db);
                    } elseif (strtolower($field_tag_name) == 'thisnum')
                    {
                        $field_tag_value = $this_num;
                    } else
                    {
                        $field_tag_value = $list_row->$field_tag_name;
                    }
                    if (is_array($field_tag_attr))
                    {
                        foreach ($field_tag_attr as $tag_attr_name => $tag_attr_value)
                        {
                            if (strtolower($tag_attr_name) == 'runphp')
                            {
                                $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value, $field_run_php_code);
                            } else
                            {
                                $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value);
                            }
                            //$field_tag_value = $this->setStringAttribute($tag_attr_name,$tag_attr_value,$field_tag_value);
                        }
                    }
                    $do_item[3][$i3][3] = $field_tag_value;
                    $list_row_string = str_ireplace($field_tag, $field_tag_value, $list_row_string);
                }
                $list_row_string = str_ireplace('{/do:' . $do_item[1] . '}', '{/do}', $list_row_string);
                $list_row_string = $this->display_do($list_row_string);
                $do_item_string .= $list_row_string;
                //$do_item_string = str_ireplace("\n",'',$do_item_string);
            }
            $templateString = str_ireplace($do_item[0], $do_item_string, $templateString);
        }
        return $templateString;
    }

    /**
     * page分页标签
     * @param $templateString				模板字符串
     * @return 								返回解析page分页标签后的字符串
     */
    protected function display_page($templateString)
    {
        $str_page = $this->JayphaTemplate->pageTag($templateString);
        //判断是否存在分页标签，不存在直接返回模板字符串
        if (count($str_page) == 0)
            return $templateString;
        foreach ($str_page as $page_item)
        {
            //判断是否存在分页配置标签，不存在则返回空，存在则进行分页
            if (count($page_item[3]) == 4)
            {
                //过滤重复记录，默认不过滤
                $distinct = $page_item[1]['distinct'];
                if (strlen($distinct) == 0)
                    $distinct = false;
                //获取字段
                $field = $page_item[1]['field'];
                if (strlen($field) > 0)
                    $field = str_ireplace('#@__', $this->db_table_prefix, $field);
                //获取表
                $tvName = $page_item[1]['table'];
                if (strlen($tvName) == 0)
                    continue;
                else
                    $tvName = str_ireplace('#@__', $this->db_table_prefix, $tvName);
                //判断是否存在关联数据表
                if (strlen($page_item[1]['joinon']) > 0 && strlen($page_item[1]['jointable']) > 0)
                {
                    $join_table = explode(',', $page_item[1][strtolower('joinTable')]);
                    $join_on = explode(',', $page_item[1][strtolower('joinOn')]);
                    $join_type = explode(',', $page_item[1][strtolower('joinType')]);
                    $db_join_arr = array();
                    for ($i = 0; $i < count($join_table); $i++)
                    {
                        $join_on[$i] = str_ireplace('#@__', $this->db_table_prefix, $join_on[$i]);
                        $join_table[$i] = str_ireplace('#@__', $this->db_table_prefix, $join_table[$i]);
                        if (!isset($join_type[$i]))
                            $join_type[$i] = 'inner';
                        if (strlen($join_type[$i]) == 0)
                            $join_type[$i] = 'inner';
                        $db_join_arr[$i] = array('tableName' => $join_table[$i], 'conditions' => $join_on[$i], 'joinType' => $join_type[$i]);
                    }
                    $tvName = array(
                        'tableName' => $tvName,
                        'db_join' => $db_join_arr
                    );
                }
                //where
                $where = array();
                if (strlen(trim($page_item[1]['where'])) > 0)
                {
                    $page_item[1]['where'] = str_ireplace('#@__', $this->db_table_prefix, $page_item[1]['where']);
                    $page_item[1]['where'] = str_ireplace(' ', '', $page_item[1]['where']);
                    foreach ($this->operational_str as $opearational_str)
                    {
                        $page_item[1]['where'] = str_ireplace($opearational_str, ' ' . $opearational_str, $page_item[1]['where']);
                    }
                    foreach ($this->operational_str2 as $opearational_str2)
                    {
                        $page_item[1]['where'] = str_ireplace($opearational_str2, ' ' . trim($opearational_str2) . ' ', $page_item[1]['where']);
                    }
                    $where['db_where'] = $page_item[1]['where'];
                }
                //where_in
                if (strlen(trim($page_item[1][strtolower('whereIn')])) > 0 && strlen(trim($page_item[1][strtolower('whereInField')])) > 0)
                {
                    $page_item[1][strtolower('whereIn')] = str_ireplace(' ', '', $page_item[1][strtolower('whereIn')]);
                    $page_item[1][strtolower('whereIn')] = explode(',', $page_item[1][strtolower('whereIn')]);
                    $page_item[1][strtolower('whereInField')] = str_ireplace('#@__', $this->db_table_prefix, $page_item[1][strtolower('whereInField')]);
                    $where['db_where_in'] = array($page_item[1][strtolower('whereInField')], $page_item[1][strtolower('whereIn')]);
                }
                //where_like
                if (strlen(trim($page_item[1]['like'])) > 0 && strlen(trim($page_item[1][strtolower('likeField')])) > 0)
                {
                    $page_item[1][strtolower('likeField')] = str_ireplace('#@__', $this->db_table_prefix, $page_item[1][strtolower('likeField')]);
                    $page_item[1]['like'] = str_ireplace(' ', '', $page_item[1]['like']);
                    $where['db_like'] = array('upper(' . $page_item[1][strtolower('likeField')] . ')' => strtoupper($page_item[1]['like']));
                }
                //where_not_like
                if (strlen(trim($page_item[1][strtolower('notLike')])) > 0 && strlen(trim($page_item[1][strtolower('notLikeField')])) > 0)
                {
                    $page_item[1][strtolower('notLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $page_item[1][strtolower('notLikeField')]);
                    $page_item[1][strtolower('notLike')] = str_ireplace(' ', '', $page_item[1][strtolower('notLike')]);
                    $where['db_not_like'] = array('upper(' . $page_item[1][strtolower('notLikeField')] . ')' => strtoupper($page_item[1][strtolower('notLike')]));
                }
                //where_or_like
                if (strlen(trim($page_item[1][strtolower('orLike')])) > 0 && strlen(trim($page_item[1][strtolower('orLikeField')])) > 0)
                {
                    $page_item[1][strtolower('orLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $page_item[1][strtolower('orLikeField')]);
                    $page_item[1][strtolower('orLike')] = str_ireplace(' ', '', $page_item[1][strtolower('orLike')]);
                    $where['db_or_like'] = array('upper(' . $page_item[1][strtolower('orLikeField')] . ')' => strtoupper($page_item[1][strtolower('orLike')]));
                }
                //where_or_not_like
                if (strlen(trim($page_item[1][strtolower('orNotLike')])) > 0 && strlen(trim($_list_item[1][strtolower('orNotLikeField')])) > 0)
                {
                    $page_item[1][strtolower('orNotLikeField')] = str_ireplace('#@__', $this->db_table_prefix, $this_item[1][strtolower('orNotLikeField')]);
                    $page_item[1][strtolower('orNotLike')] = str_ireplace(' ', '', $page_item[1][strtolower('orNotLike')]);
                    $where['db_or_not_like'] = array('upper(' . $page_item[1][strtolower('orNotLikeField')] . ')' => strtoupper($page_item[1][strtolower('orNotLike')]));
                }

                //排序
                $order = $page_item[1]['order'];
                if (strlen($order) > 0)
                {
                    $order = str_ireplace('#@__', $this->db_table_prefix, $order);
                }
                //获取记录数
                $top = $page_item[1]['top'];
                if (strlen($top) == 0)
                    $top = 0;

                $this->page_config = $page_item[3][1];
                //设置分页默认配置
                if (strlen($this->page_config['base_url']) == 0)
                {
                    $pageurl = trim(strtolower(current_url()));
                    $baseurl = trim(strtolower(base_url()));
                    $num1 = strripos($pageurl, '/');
                    if (substr($pageurl, strlen($pageurl) - 1) == '/')
                        $pageurl = substr($pageurl, 0, strlen($pageurl) - 1);
                    if (substr($baseurl, strlen($baseurl) - 1) == '/')
                        $baseurl = substr($baseurl, 0, strlen($baseurl) - 1);
                    if ($pageurl == $baseurl)
                    {
                        //首页分页(未输入默认控制器)				
                        $current_controllers = $this->config->item('default_controller');
                        $this->page_config['base_url'] = $pageurl . '/' . $current_controllers . '/index';
                    } else
                    {
                        //输入了控制器(包含首页)
                        if (!is_numeric(substr($pageurl, $num1 + 1)))
                        {
                            $this->page_config['base_url'] = current_url();
                            if (strlen($this->uri->segment(2)) == 0)
                            {
                                //只输入base_url+控制器
                                $this->page_config['base_url'] .= '/index';
                            }
                        } else
                        {
                            $this->page_config['base_url'] = substr($pageurl, 0, $num1);
                        }
                    }
                }
                $this->page_config['total_rows'] = $this->JayphaDB->getDBCount($tvName, $where);
                if (strlen($this->page_config['uri_segment']) == 0)
                {
                    $this->page_config['uri_segment'] = 3;
                }
                if (strlen($this->page_config['num_links']) == 0)
                {
                    $this->page_config['num_links'] = 4;
                }
                if (strlen($this->page_config['first_link']) == 0)
                {
                    $this->page_config['first_link'] = '|<';
                }
                if (strlen($this->page_config['last_link']) == 0)
                {
                    $this->page_config['last_link'] = '>|';
                }
                if (strlen($this->page_config['next_link']) == 0)
                {
                    $this->page_config['next_link'] = '>>';
                }
                if (strlen($this->page_config['prev_link']) == 0)
                {
                    $this->page_config['prev_link'] = '<<';
                }
                if (strlen($this->page_config['cur_tag_open']) == 0)
                {
                    $this->page_config['cur_tag_open'] = '<strong>';
                }
                if (strlen($this->page_config['cur_tag_close']) == 0)
                {
                    $this->page_config['cur_tag_close'] = '</strong>';
                }
                if (strlen($this->page_config['per_page']) == 0 || !is_numeric($this->page_config['per_page']))
                {
                    $this->page_config['per_page'] = $this->JayphaDB->getConfigValue('frontPageSize');
                }

                $num = $this->uri->segment($this->page_config['uri_segment'], 0);
                $cur_page = (int) ($num / $this->page_config['per_page']) + 1;
                //从数据库中读取记录
                $list_db = $this->JayphaDB->getDB($this->page_config['per_page'], $num, $field, $tvName, $where, $order, $distinct);
                //将字段名全部转换为小写
                $list_db2 = array();
                for ($list_db2_i = 0; $list_db2_i < count($list_db); $list_db2_i++)
                {
                    foreach ($list_db[$list_db2_i] as $key => $value)
                    {
                        $key = strtolower($key);
                        $list_db2[$list_db2_i]->$key = $value;
                    }
                }
                $list_db = $list_db2;
                unset($list_db2);

                $templateString = str_ireplace($page_item[0], $page_item[2], $templateString);
                $page_total = $this->getPageTotal($this->page_config['total_rows'], $this->page_config['per_page']);
                $list_item_string = '';
                $this_num = 0;
                foreach ($list_db as $list_row)
                {
                    $this_num++;
                    $list_row_string = $page_item[3][3];
                    for ($i3 = 0; $i3 < count($page_item[3][2]); $i3++)
                    {
                        $field_tag = $page_item[3][2][$i3][0];
                        $field_tag_name = strtolower($page_item[3][2][$i3][1]);
                        $field_tag_attr = $page_item[3][2][$i3][2];
                        @$field_run_php_code = $page_item[3][2][$i3][3];
                        switch (strtolower($field_tag_name))
                        {
                            case 'thiscount':
                                //当前页中记录总数
                                $field_tag_value = count($list_db);
                                break;
                            case 'thisnum':
                                //当前页中第几条记录
                                $field_tag_value = $this_num;
                                break;
                            case 'thistotal':
                                //总的记录数
                                $field_tag_value = $this->page_config['total_rows'];
                                break;
                            case 'thisrecord':
                                //相对总记录而言，当前记录的位置（即相对总记录数，当前记录为第几条）
                                $field_tag_value = $this_num + $num;
                                break;
                            case 'pagetotal':
                                //总页数
                                $field_tag_value = $page_total;
                                break;
                            case 'currentpage':
                                //当前页数
                                $field_tag_value = $cur_page;
                                break;
                            case 'pagesize':
                                //每页多少条记录，即分页大小
                                $field_tag_value = $this->page_config['per_page'];
                                break;
                            default:
                                //从数据库中获取字段值
                                $field_tag_value = $list_row->$field_tag_name;
                                break;
                        }
                        if (is_array($field_tag_attr))
                        {
                            foreach ($field_tag_attr as $tag_attr_name => $tag_attr_value)
                            {
                                if (strtolower($tag_attr_name) == 'runphp')
                                {
                                    $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value, $field_run_php_code);
                                } else
                                {
                                    $field_tag_value = $this->setStringAttribute($tag_attr_name, $tag_attr_value, $field_tag_value);
                                }
                                //$field_tag_value = $this->setStringAttribute($tag_attr_name,$tag_attr_value,$field_tag_value);
                            }
                        }
                        $list_row_string = str_ireplace($field_tag, $field_tag_value, $list_row_string);
                    }
                    $list_item_string .= $list_row_string;
                    //$list_item_string = str_ireplace("\n",'',$list_item_string);
                }
                $this->pagination->initialize($this->page_config);
                $temp_string = str_ireplace($page_item[3][0], $list_item_string, $templateString);
                $templateString = str_ireplace('[page:create_links/]', $this->pagination->create_links(), $temp_string);
                $templateString = str_ireplace('[page:pagetotal/]', $page_total, $templateString);
                $templateString = str_ireplace('[page:pagesize/]', $this->page_config['per_page'], $templateString);
                $templateString = str_ireplace('[page:recordcount/]', $this->page_config['total_rows'], $templateString);
                $templateString = str_ireplace('[page:currentpage/]', $cur_page, $templateString);
            } else
            {
                $templateString = str_ireplace($page_item[0], null, $templateString);
            }
        }
        return $templateString;
    }

    /**
     * 输出模板
     * @param $template					模板文件
     * @param $data						传入模板文件中的数据
     * @param $return_template_string	是否返回解析后的模板字符串，默认为直接输出至浏览器
     */
    protected function display($template, $data = null, $return_template_string = false)
    {
        //$start_t = microtime(true);
        if (strlen($this->frontCurrentTemplate) > 0)
        {
            if (substr($this->frontCurrentTemplate, strlen($this->frontCurrentTemplate) - 1) != '/')
            {
                if (substr($template, 0, 1) != '/')
                {
                    $template = $this->frontCurrentTemplate . '/' . $template;
                } else
                {
                    $template = $this->frontCurrentTemplate . $template;
                }
            } else
            {
                if (substr($template, 0, 1) != '/')
                {
                    $template = $this->frontCurrentTemplate . $template;
                } else
                {
                    $template = substr($this->frontCurrentTemplate, 0, strlen($this->frontCurrentTemplate) - 1) . $template;
                }
            }
        }
        $template_string = $this->load->view($template, $data, true);
        $template_string = $this->init($template_string);
        $template_string = $this->display_sys($template_string);
        $template_string = $this->display_inc($template_string, $data);
        $template_string = $this->display_sys($template_string);
        $template_string = $this->display_field($template_string);
        $template_string = $this->display_do($template_string);
        $template_string = $this->display_list($template_string);
        $template_string = $this->display_page($template_string);
        $template_string = $this->display_if($template_string);
        if (!is_bool($return_template_string))
            $return_template_string = false;
        if (!$return_template_string)
        {
            echo $template_string;
        } else
        {
            return $template_string;
        }
        //$end_t = microtime(true);
        //$totaltime = $end_t - $start_t;
        //echo "页面加载时间为：<span style='color:#f00; margin-right:5px;'>".$totaltime."</span>秒";
    }

    /**
     * 输出缓存模板
     * @param $template					模板文件
     * @param $data						传入模板文件中的数据
     * @param $cur_page					当前页，如果是列表的话，获取当前页的缓存
     * @param $cache_prefix				缓存文件前缀
     * @param $cache_time				缓存时间
     */
    protected function display_cache($template, $data=null, $cur_page=0, $cache_prefix='jaypha_', $cache_time = 120)
    {
        if ($cur_page != 0)
        {
            $cache_file = $cache_prefix . sha1($cur_page);
        } else
        {
            $cache_file = $cache_prefix . sha1($this->uri->segment(1) . '_' . $this->uri->segment(2));
        }
        if (!$template_string = $this->cache->file->get($cache_file))
        {
            $template_string = $this->display($template, $data, true);
            if ($cur_page != 0)
            {
                $cur_page = $this->uri->segment($this->page_config['uri_segment'], 0);
                if (is_numeric($cur_page))
                {
                    $cur_page = (int) $cur_page;
                    $page_total = $this->getPageTotal($this->page_config['total_rows'], $this->page_config['per_page']);
                    if ($cur_page >= 0 && $cur_page < $page_total * $this->page_config['per_page'] && ($cur_page % $this->page_config['per_page'] == 0))
                    {
                        $this->cache->file->save($cache_file, $template_string, $cache_time);
                    }
                }
            } else
            {
                $this->cache->file->save($cache_file, $template_string, $cache_time);
            }
        }
        echo $template_string;
    }

}

/* End of file Jaypha_Controller.php */
/* Location: ./application/core/Jaypha_Controller.php */